#include <iostream>
#include <unistd.h>
#include "RingQueue.hpp"

using namespace std;
using namespace RingQueueModual;

void *Customer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data = 0;
        rq->Pop(&data);
        printf("Custormer get a data %d\n",data);
    }
    return nullptr;
}

void *Producer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    int data = 10;

    while (true)
    {
        rq->Push(data);
        data++;
        printf("Producer produce a data %d\n",data);
        sleep(1);
    }
    return nullptr;
}

int main()
{
    RingQueue<int> *rq = new RingQueue<int>(10);

    pthread_t c1,p1;
    pthread_create(&c1, nullptr, Customer, rq);
    pthread_create(&p1, nullptr, Producer, rq);
    pthread_join(c1, nullptr);
    pthread_join(p1, nullptr);
    delete rq;
    return 0;
}